//import mapJs from '../lib/maps.js'
import {
	Et
} from "./Oak.js";
var map = null;
var marker;
let iconMap = {
	"MONITOR_RAIN": require("@/assets/images/point/monitor_rain.png"),
	"MONITOR_SW": require("@/assets/images/point/monitor_sw.png"),
	"MONITOR_REO": require("@/assets/images/point/monitor_reo.png"),
	"MONITOR_RIVER": require("@/assets/images/point/monitor_river.png"),
	"MONITOR_PIPE": require("@/assets/images/point/monitor_pipe.png"),
	"MONITOR_WATER": require("@/assets/images/point/monitor_water.png"),
	"MONITOR_RG": require("@/assets/images/point/water_danger.png"),
	"MONITOR_GC": require("@/assets/images/point/engineering_danger.png"),
	"MONITOR_aa": require("@/assets/images/point/icon_river_red.png"),
	"MONITOR_bb": require("@/assets/images/point/icon_water_red.png"),
}
export default {


	initMap() {
		map = new AMap.Map('map', {
			resizeEnable: true,
			zoom: 22, //级别
			center: [113.115622, 23.043764], //中心点坐标
			viewMode: '3D' //使用3D视图
		});
		AMap.plugin([
			'AMap.ToolBar'
		], function() {
			// 在图面添加工具条控件，工具条控件集成了缩放、平移、定位等功能按钮在内的组合控件
			map.addControl(new AMap.ToolBar({
				position: "LT",
				liteStyle: true
			}));
		});
	},
	setZoomAndCenter(data) {
		map.setZoomAndCenter(14, [data.lgtd, data.lttd]);
	},
	//请求接口渲染的地图数据
	randerMarker(locationList) {
		let addMarkerList;
		map.clearMap(); //清除marker
		addMarkerList = locationList.features.map(item => {
			let {
				coordinates
			} = item.geometry
			let {
				properties
			} = item
			let lgt = coordinates[0],
				lat = coordinates[1]
			if (!isNaN(Number(lgt)) && !isNaN(Number(lat))) {
				if(properties.isAlarm){
					let images = new AMap.Icon({
						size: new AMap.Size(45, 45),
						image: iconMap[locationList.layerId=="MONITOR_RIVER"?'MONITOR_aa':'MONITOR_bb'],
						imageSize: new AMap.Size(30, 30),
					});
					marker = new AMap.Marker({
						position: [lgt * 1, lat * 1],
						icon: images,
						offset: new AMap.Pixel(-15, -30)
					})
				}else{
					let images = new AMap.Icon({
						size: new AMap.Size(45, 45),
						image: iconMap[locationList.layerId],
						imageSize: new AMap.Size(30, 30),
					});
					marker = new AMap.Marker({
						position: [lgt * 1, lat * 1],
						icon: images,
						offset: new AMap.Pixel(-15, -30)
					})
				}
				let title = '';
				marker.on('click', function(e) {
					Et.Manager.dispatch("pointChange", properties, locationList.layerId)
				});
				marker.id = item.properties.id;
				return marker;
			} else {
				return {}
			}
		})

		map.add(addMarkerList);

		// map.setCenter([locationList[0].geometry.coordinates[0], locationList[0].geometry.coordinates[1]]); //设置地图中心点
		//设置地图显示范围
		var mybounds = new AMap.Bounds([locationList.bbox[0], locationList.bbox[1]], [locationList.bbox[2], locationList
			.bbox[3]
		]);
		map.setBounds(mybounds);
		return addMarkerList;
	},
	// moveCenter(long, lat){
	// 	map.setCenter(long, lat); //设置地图中心点
	// },
	//点击列表某条数据渲染地图数据 不请求接口
	currentMarker(currentData, title) {
		let images;
		map.clearMap(); //清除marker
		images = new AMap.Icon({
			size: new AMap.Size(25, 34),
			image: iconMap[currentData.monitorTypeCode],
			imageSize: new AMap.Size(30, 30),
		});
		marker = new AMap.Marker({
			position: [currentData.lgt * 1, currentData.lat * 1],
			icon: images,
		})
		marker.on('click', function(e) {
			this.setLabel({
				offset: new AMap.Pixel(0, -10), //设置文本标注偏移量
				content: "<div class='info'>" + title + "<i></i></div>", //设置文本标注内容
				direction: 'top' //设置文本标注方位
			});
		})

		map.add(marker);
		map.setCenter([currentData.lgt, currentData.lat]); //设置地图中心点
	},
	destroyMap() {
		map && map.destroy();
	}
}
